﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Power.DAL;
using Power;
using Power.Model;

namespace Admin.UI
{
    /// <summary>
    /// Rootlogin.xaml 的交互逻辑
    /// </summary>
    public partial class Rootlogin : Window
    {
        public Rootlogin()
        {
            InitializeComponent();
        }


        public string rootusername
        {
            get;
            set;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {

            string username = Usernabox.Text;
            string userpass = Userpasswdbox.Password;
            User op = new UserDal().GetByRootName(username);
            //string dbMd5 = op.Password; //数据库中存储的密码值
            string mymd5 = CommonHelper.GetMD5(userpass + CommonHelper.GetPasswordSalt());
            if (op == null)
            {
                MessageBox.Show("无此用户或者没有权限");
            }
            else


                if (op.Password == mymd5)
                {
                    MessageBox.Show("登录成功");
                    rootusername = username;
                    DialogResult = true;
                }

                
                else
                {
                    MessageBox.Show("用户名或者密码错误！");
                }






        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
